home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / gpr.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  13.2 KB  |  445 lines

  1. /*
  2.  * $Id: gpr.trm,v 1.6 1995/12/20 21:47:50 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - gpr.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   APOLLO's GPR windowing system
  26.  *
  27.  * AUTHORS
  28.  *  Michael Aramini
  29.  *  Roque D Oliveira , oliveria@caen.engin.umich.edu
  30.  * 
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  * 
  33.  */
  34.  
  35. /*
  36.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  37.  */
  38.  
  39. #ifndef GOT_DRIVER_H
  40. #include "driver.h"
  41. #endif
  42.  
  43. #ifdef TERM_REGISTER
  44. register_term(gpr)
  45. #endif
  46.  
  47. #ifdef TERM_PROTO
  48. TERM_PUBLIC void GPR_init __P((void));
  49. TERM_PUBLIC void GPR_graphics __P((void));
  50. TERM_PUBLIC void GPR_text __P((void));
  51. TERM_PUBLIC void GPR_linetype __P((int linetype));
  52. TERM_PUBLIC void GPR_move __P((unsigned int x, unsigned int y));
  53. TERM_PUBLIC void GPR_vector __P((unsigned int x, unsigned int y));
  54. TERM_PUBLIC void GPR_put_text __P((unsigned int x, unsigned int y, char str[]));
  55. TERM_PUBLIC int GPR_text_angle __P((int ang));
  56. TERM_PUBLIC int GPR_justify_text __P((enum JUSTIFY mode));
  57. TERM_PUBLIC void GPR_reset __P((void));
  58. /* landscape window */
  59. /*
  60. #define GPR_XMAX 720
  61. #define GPR_YMAX 450
  62. */
  63. /* portrait window */
  64. #define GPR_XMAX 585
  65. #define GPR_YMAX 735
  66. #define GPR_VCHAR 19
  67. #define GPR_HCHAR 10
  68. #define GPR_VTIC (GPR_YMAX/80)
  69. #define GPR_HTIC (GPR_XMAX/80)
  70. #endif /* TERM_PROTO */
  71.  
  72. #ifndef TERM_PROTO_ONLY
  73. #ifdef TERM_BODY
  74. void GPRold_linetype __P((int linetype));
  75. static void check __P((char *messagex));
  76. int gpr_isa_pad __P((void));
  77. #include <apollo/base.h>
  78. #include <apollo/error.h>
  79. #include <apollo/gpr.h>
  80. #include <apollo/pad.h>
  81.  
  82. #define GPR_XLAST (GPR_XMAX - 1)
  83. #define GPR_YLAST (GPR_YMAX - 1)
  84.  
  85.  
  86. gpr_$direction_t  gpr_path=gpr_$right;
  87. int               gpr_ang=0;            /* text angle, 0=horizontal, 1=vertical */
  88. enum JUSTIFY      gpr_justify=LEFT;     /* text is flush left */
  89.  
  90. static status_$t  status;
  91. unsigned int      Debug    = 0;         /* set it to 1 when debugging program */
  92.  
  93.  
  94. static void check(messagex)
  95. char *messagex;
  96. {
  97.   if (status.all = status_$ok)
  98.   {
  99.     error_$print(status);
  100.     printf("Error occurred while %s.\n", messagex);
  101.   }
  102. }
  103.  
  104. /* return whether stdout is a DM pad . Called by term.c */
  105. int gpr_isa_pad()
  106. {
  107.     pad_$isa(1, &status);
  108.     return (status.all == status_$ok);
  109. }
  110.  
  111.  
  112. TERM_PUBLIC void GPR_init()
  113. {
  114.   gpr_$offset_t dm_bitmap_size;
  115.   gpr_$bitmap_desc_t dm_bitmap_desc;
  116.   pad_$window_desc_t window;
  117.   short font_id;
  118.   stream_$id_t stream_id;
  119.   static gpr_$rgb_plane_t  hi_plane;
  120.   static gpr_$disp_char_t  display_characteristics;
  121.   static float             screen_size_r_width,screen_size_r_height ;
  122.   static short int         disp_len = sizeof(gpr_$disp_char_t);
  123.   static short int         disp_len_returned;
  124.  
  125.  
  126.   /* open a pad to do graphics in */
  127.   window.top    = 0;
  128.   window.left   = 0;
  129.   window.width  = GPR_XMAX + 10; /* 10 accounts for width of window border */
  130.   window.height = GPR_YMAX + 35; /* 35 accounts for height of window border */
  131.   pad_$create_window("",(short)0,pad_$transcript,(short)1,window,&stream_id,&status);
  132.   check("pad_$create_window");
  133.  
  134. /*  pad_$set_full_window(stream_id,(short) 1,&window, &status); */
  135. /*  pad_$set_border (stream_id,(short) 1, true, &status); */
  136.   pad_$set_scale (stream_id,(short) 1,(short) 1, &status);
  137.   pad_$set_auto_close(stream_id, (short) 1, true, &status );
  138.  
  139.   gpr_$inq_disp_characteristics(gpr_$direct,stream_id,disp_len,&display_characteristics,&disp_len_returned,&status);
  140.   check("in gpr_$inq_display_characteristics");
  141.   screen_size_r_width    = (float) display_characteristics.x_window_size;    /*x_window_size in pixels */
  142.   screen_size_r_height   = (float) display_characteristics.y_window_size;    /*y_window_size in pixels */
  143.   hi_plane  = display_characteristics.n_planes - 1;  
  144.   if(Debug) printf("width=%f height=%f \n",screen_size_r_width,screen_size_r_height);
  145.  
  146.   dm_bitmap_size.x_size = 1280;
  147.   dm_bitmap_size.y_size = 1024;
  148.   gpr_$init(gpr_$direct,stream_id,dm_bitmap_size,hi_plane,&dm_bitmap_desc,&status); 
  149.   check("in gpr_$init");
  150. /*
  151.   gpr_$set_obscured_opt(gpr_$pop_if_obs, &status); 
  152.   check("in gpr_$set_obscured_opt");
  153. */
  154.   gpr_$set_auto_refresh(true, &status); 
  155.   check("in gpr_$set_auto_refresh");
  156.  
  157.   /* load a font and make it current */
  158.   gpr_$load_font_file("f7x13", 5, &font_id, &status);
  159.   check("in gpr_$load_font_file");
  160.   gpr_$set_text_font(font_id, &status);
  161.   check("in gpr_$set_text_font");
  162.  
  163.   /* set up color values */
  164.   gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  165.   check("in gpr_set_draw_value");
  166.   gpr_$set_text_background_value((gpr_$pixel_value_t)(-1), &status); /* trans */
  167.   check("in gpr_$set_text_background_value");
  168.   gpr_$set_text_value((gpr_$pixel_value_t)7, &status);  /* white */
  169.   check("in gpr_$set_text_value");
  170. }
  171.  
  172.  
  173. TERM_PUBLIC void GPR_graphics()
  174. {
  175.   gpr_$coordinate_t locx,locy,marker_size;
  176.  
  177.   (void) gpr_$acquire_display(&status);
  178.   check("in gpr_$acquire display");
  179.   gpr_$clear((gpr_$pixel_value_t)0, &status);  /* black */
  180.   check("in gpr_$clear");
  181.  
  182.   if(Debug) 
  183.    {
  184.     marker_size = (short) 10;  
  185.  
  186.     locx = (short) 5;
  187.     locy = (short) 5;
  188.     gpr_$set_draw_value((gpr_$pixel_value_t)2, &status);  /* white */
  189.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  190.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  191.     gpr_$move( locx, (locy + marker_size/2),&status);
  192.     gpr_$line( locx, (locy - marker_size/2),&status);
  193.     
  194.     locx = (short) (GPR_XMAX -1 - 5);
  195.     locy = (short) 5;
  196.     gpr_$set_draw_value((gpr_$pixel_value_t)3, &status);  /* white */
  197.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  198.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  199.     gpr_$move( locx, (locy + marker_size/2),&status);
  200.     gpr_$line( locx, (locy - marker_size/2),&status);
  201.     
  202.     locx = (short) 5;
  203.     locy = (short) (GPR_YMAX -1 - 5);
  204.     gpr_$set_draw_value((gpr_$pixel_value_t)4, &status);  /* white */
  205.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  206.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  207.     gpr_$move( locx, (locy + marker_size/2),&status);
  208.     gpr_$line( locx, (locy - marker_size/2),&status);
  209.     
  210.     locx = (short) (GPR_XMAX -1 - 5);
  211.     locy = (short) (GPR_YMAX -1 - 5);
  212.     gpr_$set_draw_value((gpr_$pixel_value_t)5, &status);  /* white */
  213.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  214.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  215.     gpr_$move( locx, (locy + marker_size/2),&status);
  216.     gpr_$line( locx, (locy - marker_size/2),&status);
  217.     
  218.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  219.     check("in gpr_$set_draw_value");
  220.    } /* end if(Debug) */
  221.  
  222. }
  223.  
  224.  
  225. TERM_PUBLIC void GPR_text()
  226. {
  227.   gpr_$release_display(&status);
  228.   check("gpr_$release_display");
  229. }
  230.  
  231.  
  232. void GPRold_linetype(linetype)
  233. int linetype;
  234. {
  235.   static gpr_$line_pattern_t patterns[2+5] = {
  236.       { 0xFFFF },   /* solid              1111111111111111 */
  237.       { 0x3FFF },   /* very long dashed   0011111111111111 */
  238.       { 0xFFFF },   /* solid              1111111111111111 */
  239.       { 0x5555 },   /* dotted             0101010101010101 */
  240.       { 0x3333 },   /* short dashed       0011001100110011 */
  241.       { 0xB5AD },   /* dot short-dashed   1011010110101101 */
  242.       { 0x3FFF }    /* very long dashed   0011111111111111 */
  243.                                              };
  244.   if (linetype >= 5) linetype %= 5;
  245.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  246.   check("in gpr_$set_line_pattern");
  247. }
  248.  
  249. TERM_PUBLIC void GPR_linetype(linetype)
  250. int linetype;
  251. {
  252.   static gpr_$line_pattern_t patterns[2+7] = {
  253.       { 0xFFFF },   /* solid              1111111111111111 */
  254.       { 0x1111 },   /* long-spaced dotted 0001000100010001 */
  255.       { 0xFFFF },   /* solid              1111111111111111 */
  256.       { 0x5555 },   /* dotted             0101010101010101 */
  257.       { 0x3333 },   /* short  dashed      0011001100110011 */
  258.       { 0x7777 },   /* medium dashed      0111011101110111 */
  259.       { 0x3F3F },   /* long   dashed      0011111100111111 */
  260.       { 0x0F0F },   /* long-spaced dashed 0000111100001111 */
  261.       { 0x5F5F }    /* dot dashed         0101111101011111 */
  262.                                              };
  263.   if (linetype >= 7) linetype %= 7;
  264.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  265.   check("in gpr_$set_line_pattern");
  266.  
  267. /*
  268.   gpr_$set_draw_value((gpr_$pixel_value_t)(linetype + 1), &status);
  269.   check("in gpr_$set_draw_value");
  270. */
  271. }
  272.  
  273.  
  274. TERM_PUBLIC void GPR_move(x, y)
  275. unsigned int x, y;
  276. {
  277.   gpr_$move((short)x, (short)(GPR_YMAX -1 - y), &status);
  278.   check("in gpr_$move");
  279. }
  280.  
  281.  
  282. TERM_PUBLIC void GPR_vector(x, y)
  283. unsigned int x, y;
  284. {
  285.   gpr_$line((short)x, (short)(GPR_YMAX -1 - y), &status);
  286.   check("in gpr_$line");
  287. }
  288.  
  289.  
  290. TERM_PUBLIC void GPR_put_text(x,y,str)
  291. unsigned int x,y;        /* reference point of string */
  292. char str[];              /* the text */
  293. {
  294.   gpr_$coordinate_t xgpr,ygpr;
  295.   gpr_$offset_t     str_size_in_pixels;
  296.   short int         str_len;     
  297.  
  298.   gpr_$coordinate_t locx,locy,marker_size;
  299.  
  300.   if(Debug) 
  301.    {
  302.     locx = (short) x;
  303.     locy = (short) (GPR_YMAX -1 - y);
  304.     marker_size = (short) 20;  
  305.     gpr_$set_draw_value((gpr_$pixel_value_t)1, &status);  /* white */
  306.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  307.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  308.     gpr_$move( locx, (locy + marker_size/2),&status);
  309.     gpr_$line( locx, (locy - marker_size/2),&status);
  310.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  311.    }
  312.  
  313.   xgpr = (short) x;
  314.   ygpr = (short) (GPR_YMAX -1 - y); 
  315.   gpr_$set_text_path(gpr_path, &status); 
  316.   check("gpr_$set_text_path");
  317.  
  318.   str_len = (short) strlen(str);
  319.   gpr_$inq_text_extent(str,str_len,&str_size_in_pixels,&status); /* Calculate how much space (in pixels) the string requires */    
  320.   check("in gpr_$inq_text_extent");
  321.  
  322.   switch (gpr_justify) 
  323.    {
  324.     case LEFT :
  325.         {
  326.          switch (gpr_path) 
  327.           {
  328.            case gpr_$up :           /* vertical */
  329.                {
  330.                 if(Debug) printf("LEFT and up , str=%s\n",str);
  331.                 break;
  332.                }
  333.            case gpr_$right :        /* horizontal */
  334.                {
  335.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  336.                 if(Debug) printf("LEFT and right, str=%s \n",str);
  337.                 break;
  338.                }
  339.           }
  340.          break;
  341.         }
  342.  
  343.     case CENTRE :
  344.         {  
  345.          switch (gpr_path) 
  346.           {
  347.            case gpr_$up :           /* vertical */
  348.                {
  349.                 xgpr = xgpr + str_size_in_pixels.x_size/2;
  350.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  351.                 if(Debug) printf("CENTRE and up, str=%s \n",str);
  352.                 break;
  353.                }
  354.            case gpr_$right :        /* horizontal */
  355.                {
  356.                 xgpr = xgpr - str_size_in_pixels.x_size/2;
  357.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  358.                 if(Debug) printf("CENTRE and right, str=%s \n",str);
  359.                 break;
  360.                }
  361.           }
  362.          break;
  363.         }
  364.     case RIGHT :
  365.         {
  366.          switch (gpr_path) 
  367.           {
  368.            case gpr_$up :           /* vertical */
  369.                {
  370.                 ygpr = ygpr + str_size_in_pixels.y_size;
  371.                 if(Debug) printf("RIGHT and up, str=%s \n",str);
  372.                 break;
  373.                }
  374.            case gpr_$right :        /* horizontal */
  375.                {
  376.                 xgpr = xgpr - str_size_in_pixels.x_size;
  377.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  378.                 if(Debug) printf("RIGHT and right, str=%s \n",str);
  379.                 break;
  380.                }
  381.           }
  382.          break;
  383.         }
  384.    }
  385.  
  386.   gpr_$move(xgpr,ygpr,&status);
  387.   check("in gpr_$move");
  388.   gpr_$text(str, str_len, &status);
  389.   check("in gpr_$text");
  390. }
  391.  
  392. TERM_PUBLIC int GPR_text_angle(ang)
  393. int ang;
  394. {   
  395.     if (gpr_ang != ang)
  396.       {
  397.         gpr_ang  = ang;
  398.         gpr_path = (gpr_ang == 1 ? gpr_$up : gpr_$right);
  399.       }
  400.     return (TRUE);
  401. }
  402.  
  403. TERM_PUBLIC int GPR_justify_text(mode)
  404. enum JUSTIFY mode;
  405. {
  406.     gpr_justify = mode;
  407.     return (TRUE);
  408. }
  409.  
  410. TERM_PUBLIC void GPR_reset()
  411. {
  412.   gpr_$terminate(false, &status);
  413.   check("in gpr_$terminate");
  414. }
  415.  
  416. #endif /* TERM_BODY */
  417.  
  418. #ifdef TERM_TABLE
  419.  
  420. TERM_TABLE_START(gpr_driver)
  421.        "gpr", "Apollo Graphics Primitive Resource, fixed-size window",
  422.        GPR_XMAX, GPR_YMAX, GPR_VCHAR, GPR_HCHAR,
  423.        GPR_VTIC, GPR_HTIC, options_null, GPR_init, GPR_reset,
  424.        GPR_text, null_scale, GPR_graphics, GPR_move, GPR_vector,
  425.        GPR_linetype, GPR_put_text, GPR_text_angle,
  426.        GPR_justify_text, line_and_point, do_arrow, set_font_null
  427. TERM_TABLE_END(gpr_driver)
  428.  
  429. #undef LAST_TERM
  430. #define LAST_TERM gpr_driver
  431.  
  432. #endif /* TERM_TABLE */
  433. #endif /* TERM_PROTO_ONLY */
  434.  
  435. /*
  436.  * NAME: gpr
  437.  *
  438.  * OPTIONS: none
  439.  *
  440.  * SUPPORTS: Apollo Graphics Primitive Resource, fixed-size window
  441.  *
  442.  * Further Info: There is another terminal (apollo) with resizeable
  443.  *         windows.
  444.  *
  445.  */